#include <iostream>
#include <vector>
#include <string>
#include <unordered_set>
#include <climits>

using namespace std;

// 1888. 使二进制字符串字符交替的最少反转次数
// https://leetcode.cn/problems/minimum-number-of-flips-to-make-the-binary-string-alternating/description/

class Solution
{
public:
    int minFlips(string s)
    {
        int n = s.size();
        string str = s + s;
        string target1, target2;
        for (int i = 0; i < str.size(); i++)
        {
            target1 += (i % 2 == 0) ? '1' : '0';
            target2 += (i % 2 == 0) ? '0' : '1';
        }

        int ans = INT_MAX;
        int diff1 = 0;
        int diff2 = 0;
        int left = 0;
        for (int i = 0; i < n * 2; i++)
        {
            int curCh = str[i];
            if(target1[i] != curCh){
                diff1++;
            }
            if(target2[i] != curCh){
                diff2++;
            }
            if(i + left + 1 < n){
                continue;
            }
            ans = min(diff1, min(diff2, ans));
            if(str[left] != target1[left]){
                diff1--;
            }
            if(str[left] != target2[left]){
                diff2--;
            }
            left++;
        }

        return ans;
    }
};

int main()
{
    return 0;
}